package com.sat.wisdom.Utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Project:Wisdom
 * Package:com.sat.wisdom.Utils
 * Created by 透野君爱打奶炮 on 2018-04-10 at 18:28
 */
public class SpUtil {
    /**
     * 设置boolean
     * @param context 上下文环境
     * @param key key
     * @param value value
     */
    public static void setBoolean(Context context,String key,boolean value){
        SharedPreferences sp = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
        sp.edit().putBoolean(key,value).apply();
    }

    /**
     * 获取boolean，默认返回false
     * @param context 上下文环境
     * @param key key
     * @return
     */
    public static boolean getBoolean(Context context,String key){
        SharedPreferences sp = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
        return sp.getBoolean(key,false);
    }

    /**
     * 设置String
     * @param context 上下文环境
     * @param key key
     * @param value value
     */
    public static void setString(Context context,String key,String value){
        SharedPreferences sp = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
        sp.edit().putString(key,value).apply();
    }

    /**
     * 获取String，默认返回null
     * @param context 上下文环境
     * @param key key
     * @return
     */
    public static String getString(Context context,String key){
        SharedPreferences sp = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
        return sp.getString(key,null);
    }

    /**
     * 设置int
     * @param context 上下文环境
     * @param key key
     * @param value value
     */
    public static void setInt(Context context,String key,int value){
        SharedPreferences sp = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
        sp.edit().putInt(key,value).apply();
    }

    /**
     * 获取boolean，默认返回false
     * @param context 上下文环境
     * @param key key
     * @return
     */
    public static int getInt(Context context,String key){
        SharedPreferences sp = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
        return sp.getInt(key,0);
    }

}
